﻿Public Class MASPRODUCT
    
    Private MPDPRDCODE = Nothing
    Private CODE = Nothing
    Private PRDNAME = Nothing
    Private PRDCAT = Nothing
    Private CCODE = Nothing
    Private RCODE = Nothing
    Private ICCODE = Nothing
    Private IRCODE = Nothing
    Private HCCODE = Nothing
    Private HRCODE = Nothing
    Private B_UNIT = Nothing
    Private S_UNIT = Nothing
    Private U_UNIT = Nothing
    Private AVG_COST = Nothing
    Private LAST_COST = Nothing
    Private OPDPRC = Nothing
    Private IPDPRC = Nothing
    Private MPDSTATUS = Nothing
    Private F_STK = Nothing
    Private F_PROMO = Nothing
    Private F_PRC = Nothing
    Private F_LOT = Nothing
    Private QFP = Nothing
    Private F_OAUTO = Nothing
    Private F_IAUTO = Nothing
    Private F_FC = Nothing

    Private SelectMasproduct = "SELECT `prdcode`,`prdname` as 'รายการ',masprdcats.`prdcat`,masprdcats.`catname` as 'ชนิดสินค้า',finchcode.`ccode`,finchcode.`name` as 'รหัสรายได้',finrecode.`rcode`,finrecode.`name` as 'รหัสรายรับทางการเงิน',0 as 'เลือก',masproduct.`status` as 'สถานะการเปิดใช้งาน' FROM masproduct LEFT JOIN (SELECT `prdcat`,`catname` FROM masprdcats) as masprdcats on masproduct.`prdcat` = masprdcats.`prdcat` LEFT JOIN (SELECT `ccode`,`name` FROM finchcode WHERE `status` = 1) as finchcode on masproduct.`ccode` = finchcode.`ccode` LEFT JOIN (SELECT `rcode`,`name` FROm finrecode WHERE `status` = 1) as finrecode on masproduct.`rcode` = finrecode.`rcode`"
    Dim connect As CONDB = CONDB.NewConnection

    Property SelectMasproduct_() As String
        Get
            Return SelectMasproduct
        End Get
        Set(value As String)

        End Set
    End Property
    Property MPDPRDCODE_ As Integer
        Get
            Return MPDPRDCODE
        End Get
        Set(value As Integer)
            MPDPRDCODE = value
        End Set
    End Property

    Property CODE_ As String
        Get
            Return CODE
        End Get
        Set(value As String)
            CODE = value
        End Set
    End Property

    Property PRDNAME_ As String
        Get
            Return PRDNAME
        End Get
        Set(value As String)
            PRDNAME = value
        End Set
    End Property

    Property PRDCAT_ As Integer
        Get
            Return PRDCAT
        End Get
        Set(value As Integer)
            PRDCAT = value
        End Set
    End Property

    Property CCODE_ As Integer
        Get
            Return CCODE
        End Get
        Set(value As Integer)
            CCODE = value
        End Set
    End Property

    Property RCODE_ As Integer
        Get
            Return RCODE
        End Get
        Set(value As Integer)
            RCODE = value
        End Set
    End Property

    Property ICCODE_ As Integer
        Get
            Return ICCODE
        End Get
        Set(value As Integer)
            ICCODE = value
        End Set
    End Property

    Property IRCODE_ As Integer
        Get
            Return IRCODE
        End Get
        Set(value As Integer)
            IRCODE = value
        End Set
    End Property

    Property HCCODE_ As Integer
        Get
            Return HCCODE
        End Get
        Set(value As Integer)
            HCCODE = value
        End Set
    End Property

    Property HRCODE_ As Integer
        Get
            Return HRCODE
        End Get
        Set(value As Integer)
            HRCODE = value
        End Set
    End Property

    Property B_UNIT_ As Integer
        Get
            Return B_UNIT
        End Get
        Set(value As Integer)
            B_UNIT = value
        End Set
    End Property

    Property S_UNIT_ As Integer
        Get
            Return S_UNIT
        End Get
        Set(value As Integer)
            S_UNIT = value
        End Set
    End Property

    Property U_UNIT_ As Integer
        Get
            Return U_UNIT
        End Get
        Set(value As Integer)
            U_UNIT = value
        End Set
    End Property

    Property AVG_COST_ As Double
        Get
            Return AVG_COST
        End Get
        Set(value As Double)
            AVG_COST = value
        End Set
    End Property

    Property LAST_COST_ As Double
        Get
            Return LAST_COST
        End Get
        Set(value As Double)
            LAST_COST = value
        End Set
    End Property

    Property OPDPRC_ As Double
        Get
            Return OPDPRC
        End Get
        Set(value As Double)
            OPDPRC = value
        End Set
    End Property

    Property IPDPRC_ As Double
        Get
            Return IPDPRC
        End Get
        Set(value As Double)
            IPDPRC = value
        End Set
    End Property

    Property MPDSTATUS_ As Boolean
        Get
            Return MPDSTATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                MPDSTATUS = 1
            Else
                MPDSTATUS = 0
            End If
        End Set
    End Property

    Property F_STK_ As Boolean
        Get
            Return F_STK
        End Get
        Set(value As Boolean)
            If value = True Then
                F_STK = 1
            Else
                F_STK = 0
            End If
        End Set
    End Property

    Property F_PROMO_ As Boolean
        Get
            Return F_PROMO
        End Get
        Set(value As Boolean)
            If value = True Then
                F_PROMO = 1
            Else
                F_PROMO = 0
            End If
        End Set
    End Property

    Property F_PRC_ As Boolean
        Get
            Return F_PRC
        End Get
        Set(value As Boolean)
            If value = True Then
                F_PRC = 1
            Else
                F_PRC = 0
            End If
        End Set
    End Property

    Property F_LOT_ As Boolean
        Get
            Return F_LOT
        End Get
        Set(value As Boolean)
            If value = True Then
                F_LOT = 1
            Else
                F_LOT = 0
            End If
        End Set
    End Property

    Property QFP_ As Integer
        Get
            Return QFP
        End Get
        Set(value As Integer)
            QFP = value
        End Set
    End Property

    Property F_OAUTO_ As Boolean
        Get
            Return F_OAUTO
        End Get
        Set(value As Boolean)
            If value = True Then
                F_OAUTO = 1
            Else
                F_OAUTO = 0
            End If
        End Set
    End Property

    Property F_IAUTO_ As Boolean
        Get
            Return F_IAUTO
        End Get
        Set(value As Boolean)
            If value = True Then
                F_IAUTO = 1
            Else
                F_IAUTO = 0
            End If
        End Set
    End Property

    Property F_FC_ As Boolean
        Get
            Return F_FC
        End Get
        Set(value As Boolean)
            If value = True Then
                F_FC = 1
            Else
                F_FC = 0
            End If
        End Set
    End Property

    Public Function makeMasproductInsertSQL() As String
        Dim sql1 As String = ""
        Dim sql2 As String = ""
        Dim sql3 As String = ""

        'sql2 += "PRDCODE, "
        'sql3 += "'" & MPDPRDCODE & "' , "

        If CODE IsNot Nothing Or CODE <> "" Then
            sql2 += "CODE, "
            sql3 += "'" & CODE & "', "
        Else
            sql2 += "CODE, "
            sql3 += "default, "
        End If

        If PRDNAME IsNot Nothing Or PRDNAME <> "" Then
            sql2 += "PRDNAME, "
            sql3 += "'" & PRDNAME & "', "
        Else
            sql2 += "PRDNAME, "
            sql3 += "default, "
        End If

        If PRDCAT IsNot Nothing Then
            sql2 += "PRDCAT, "
            sql3 += "'" & PRDCAT & "', "
        Else
            sql2 += "PRDCAT, "
            sql3 += "default, "
        End If

        If CCODE IsNot Nothing Then
            sql2 += "CCODE, "
            sql3 += "'" & CCODE & "', "
        Else
            sql2 += "CCODE, "
            sql3 += "default, "
        End If

        If RCODE IsNot Nothing Then
            sql2 += "RCODE, "
            sql3 += "'" & RCODE & "', "
        Else
            sql2 += "RCODE, "
            sql3 += "default, "
        End If

        If ICCODE IsNot Nothing Then
            sql2 += "ICCODE, "
            sql3 += "'" & ICCODE & "', "
        Else
            sql2 += "ICCODE, "
            sql3 += "default, "
        End If

        If IRCODE IsNot Nothing Then
            sql2 += "IRCODE, "
            sql3 += "'" & IRCODE & "', "
        Else
            sql2 += "IRCODE, "
            sql3 += "default, "
        End If

        If HCCODE IsNot Nothing Then
            sql2 += "HCCODE, "
            sql3 += "'" & HCCODE & "', "
        Else
            sql2 += "HCCODE, "
            sql3 += "default, "
        End If

        If HRCODE IsNot Nothing Then
            sql2 += "HRCODE, "
            sql3 += "'" & HRCODE & "', "
        Else
            sql2 += "HRCODE, "
            sql3 += "default, "
        End If

        If B_UNIT IsNot Nothing Then
            sql2 += "B_UNIT, "
            sql3 += "'" & B_UNIT & "' , "
        Else
            sql2 += "B_UNIT, "
            sql3 += "default, "
        End If

        If S_UNIT IsNot Nothing Then
            sql2 += "S_UNIT, "
            sql3 += "'" & S_UNIT & "', "
        Else
            sql2 += "S_UNIT, "
            sql3 += "default, "
        End If

        If U_UNIT IsNot Nothing Then
            sql2 += "U_UNIT, "
            sql3 += "'" & U_UNIT & "', "
        Else
            sql2 += "U_UNIT, "
            sql3 += "default, "
        End If

        If AVG_COST IsNot Nothing Then
            sql2 += "AVG_COST, "
            sql3 += "'" & AVG_COST & "', "
        Else
            sql2 += "AVG_COST, "
            sql3 += "default, "
        End If

        If LAST_COST IsNot Nothing Then
            sql2 += "LAST_COST, "
            sql3 += "'" & LAST_COST & "', "
        Else
            sql2 += "LAST_COST, "
            sql3 += "default, "
        End If

        If OPDPRC IsNot Nothing Then
            sql2 += "OPDPRC, "
            sql3 += "'" & OPDPRC & "', "
        Else
            sql2 += "OPDPRC, "
            sql3 += "default, "
        End If

        If IPDPRC IsNot Nothing Then
            sql2 += "IPDPRC, "
            sql3 += "'" & IPDPRC & "', "
        Else
            sql2 += "IPDPRC, "
            sql3 += "default, "
        End If

        If MPDSTATUS IsNot Nothing Then
            sql2 += "STATUS, "
            sql3 += "'" & MPDSTATUS & "', "
        Else
            sql2 += "STATUS, "
            sql3 += "default, "
        End If

        If F_STK IsNot Nothing Then
            sql2 += "F_STK, "
            sql3 += "'" & F_STK & "', "
        Else
            sql2 += "F_STK, "
            sql3 += "default, "
        End If

        If F_PROMO IsNot Nothing Then
            sql2 += "F_PROMO, "
            sql3 += "'" & F_PROMO & "', "
        Else
            sql2 += "F_PROMO, "
            sql3 += "default, "
        End If

        If F_PRC IsNot Nothing Then
            sql2 += "F_PRC, "
            sql3 += "'" & F_PRC & "', "
        Else
            sql2 += "F_PRC, "
            sql3 += "default, "
        End If

        If F_LOT IsNot Nothing Then
            sql2 += "F_LOT, "
            sql3 += "'" & F_LOT & "', "
        Else
            sql2 += "F_LOT, "
            sql3 += "default, "
        End If

        If F_OAUTO IsNot Nothing Then
            sql2 += "F_OAUTO, "
            sql3 += "'" & F_OAUTO & "', "
        Else
            sql2 += "F_OAUTO, "
            sql3 += "default, "
        End If

        If F_IAUTO IsNot Nothing Then
            sql2 += "F_IAUTO, "
            sql3 += "'" & F_IAUTO & "', "
        Else
            sql2 += "F_IAUTO, "
            sql3 += "default, "
        End If

        If F_FC IsNot Nothing Then
            sql2 += "F_FC, "
            sql3 += "'" & F_FC & "', "
        Else
            sql2 += "F_FC, "
            sql3 += "default, "
        End If

        If QFP IsNot Nothing Then
            sql2 += "QFP"
            sql3 += "'" & QFP & "'"
        Else
            sql2 += "QFP"
            sql3 += "default"
        End If

        sql1 += "INSERT INTO masproduct (" & sql2 & ") VALUES (" & sql3 & ");"
        Return sql1
    End Function

    Public Function makeMasproductEditSQL() As String
        Dim sql As String = ""
        sql += "UPDATE masproduct SET "

        If CODE IsNot Nothing Or CODE <> "" Then
            sql += "code = '" & CODE & "', "
        End If

        If PRDNAME IsNot Nothing Or PRDNAME <> "" Then
            sql += "PRDNAME = '" & PRDNAME & "', "
        End If

        If CCODE <> 0 Or CCODE IsNot Nothing Then
            sql += "CCODE = '" & CCODE & "', "
        End If

        If RCODE <> 0 Or RCODE IsNot Nothing Then
            sql += "RCODE = '" & RCODE & "', "
        End If

        If ICCODE <> 0 Or ICCODE IsNot Nothing Then
            sql += "ICCODE = '" & ICCODE & "', "
        End If

        If IRCODE <> 0 Or IRCODE IsNot Nothing Then
           sql += "IRCODE = '" & IRCODE & "', "
        End If

        If HCCODE <> 0 Or HCCODE IsNot Nothing Then
           sql += "HCCODE = '" & HCCODE & "', "
        End If

        If HRCODE <> 0 Or HRCODE IsNot Nothing Then
            sql += "HRCODE = '" & HRCODE & "', "
        End If

        If B_UNIT <> 0 Or B_UNIT IsNot Nothing Then
            sql += "B_UNIT = '" & B_UNIT & "', "
        End If

        If S_UNIT <> 0 Or S_UNIT IsNot Nothing Then
            sql += "S_UNIT = '" & S_UNIT & "', "
        End If

        If U_UNIT <> 0 Or U_UNIT IsNot Nothing Then
            sql += "U_UNIT = '" & U_UNIT & "', "
        End If

        If AVG_COST IsNot Nothing Then
            sql += "AVG_COST = '" & AVG_COST & "', "
        End If

        If LAST_COST IsNot Nothing Then
            sql += "LAST_COST = '" & LAST_COST & "', "
        End If

        If OPDPRC IsNot Nothing Then
            sql += "OPDPRC = '" & OPDPRC & "', "
        End If

        If IPDPRC IsNot Nothing Then
            sql += "IPDPRC = '" & IPDPRC & "', "
        End If

        If MPDSTATUS IsNot Nothing Then
            sql += "STATUS = '" & MPDSTATUS & "', "
        End If

        If F_STK IsNot Nothing Then
            sql += "F_STK = '" & F_STK & "', "
        End If

        If F_PROMO IsNot Nothing Then
            sql += "F_PROMO = '" & F_PROMO & "', "
        End If

        If F_PRC IsNot Nothing Then
            sql += "F_PRC = '" & F_PRC & "', "
        End If

        If F_LOT IsNot Nothing Then
            sql += "F_LOT = '" & F_LOT & "', "
        End If

        If QFP IsNot Nothing Then
            sql += "QFP = '" & QFP & "', "
        End If

        If F_OAUTO IsNot Nothing Then
            sql += "F_OAUTO = '" & F_OAUTO & "', "
        End If

        If F_IAUTO IsNot Nothing Then
            sql += "F_IAUTO = '" & F_IAUTO & "', "
        End If

        If F_IAUTO IsNot Nothing Then
            sql += "F_FC = '" & F_FC & "', "
        End If

        sql += "PRDCAT = '" & PRDCAT & "' "

        sql += "WHERE PRDCODE = '" & MPDPRDCODE & "';"

        Return sql
    End Function

End Class
